<?php
$name = "";
$parent_id = 0;
$valid="";
$access ="";
$metakey = "";
$metadesc = "";
$cat_type =""; 
$is_menu = 0;
$is_feature = 0;
$ordering = 0;
$desc = "";
$link = "";
if(!empty($category)){
    $name = $this->_global->_unserialize($category->cat_name);
    if(!empty($name[$this->session->userdata('lan')]))
    $name = $name[$this->session->userdata('lan')]['title'];
    else
    $name = 'Không tồn tại tên sản phẩm theo ngôn ngữ hiện tại';
    $parent_id = $category->parent_id;
    $desc = $this->_global->_unserialize($category->cat_desc);
    if(!isset($desc)){
        $desc ='Mô tả ko tồn tại';
    }else
    if(isset($desc[$this->session->userdata('lan')]['cat_desc']))
    $desc = $desc[$this->session->userdata('lan')]['cat_desc'];
    else
    $desc ="";
    $valid = $category->valid;
    $access = $category->access;
    $metakey = $category->metakey;
    $metadesc = $category->metadesc;
    $cat_type= $category->cat_type;
    $is_menu=$category->is_menu;
    $ordering = $category->ordering;
    $is_feature = $category->is_feature;
    $link = $category->link;
    
}
?>

<div class="" id="myModal" >
  <div class="modal-header">
    <h3 style="text-transform: capitalize;"><?php echo $action;?> Category</h3>
  </div>
<?php echo form_open('administrator/category/index/'.$this->uri->rsegment(3) .'/save') ?>

<label for="cat_name">Category name:</label><input type="text" value="<?php echo $name; ?>" name="cat_name" id="cat_name" />
<label for="cat_name">Category Description:</label>
<textarea name="cat_desc" id="post_desc" style="width: 100%;height: 100px;"><?php echo $desc ?></textarea>

    <label for="cat_type">Category Type:</label>
        
            <select name="cat_type">
                <option value="shop"  <?php echo $cat_type=="shop"?"selected='selected'":"" ?>>Shop</option>
                <option value="article" <?php echo $cat_type=="article"?"selected='selected'":"" ?>>News</option>
                <option value="slideshow" <?php echo $cat_type=="slideshow"?"selected='selected'":"" ?>>Slideshow</option>
                <option value="contact" <?php echo $cat_type=="contact"?"selected='selected'":"" ?>>Contact</option>
                <option value="gallery" <?php echo $cat_type=="gallery"?"selected='selected'":"" ?>>Gallery</option>
                <option value="link" <?php echo $cat_type=="link"?"selected='selected'":"" ?>>Link</option>
                <option value="frontend" <?php echo $cat_type=="link"?"selected='selected'":"" ?>>Frontend</option>
                <option value="video" <?php echo $cat_type=="video"?"selected='selected'":"" ?>>Video</option>
                <option value="header" <?php echo $cat_type=="header"?"selected='selected'":"" ?>>Header</option>
            </select>
            <label for="parent">Parent:</label>
            <select name="parent_id">
                <option value="0">None</option>
                <?php 
                
                if(count($categories)>0):?>
                    <?php foreach($categories as $cat):
                        $cat_name = $this->_global->_unserialize($cat->cat_name)
                    ?>
                        <option  <?php echo $cat->cat_id==$parent_id?"selected='selected'":"" ?> value="<?php echo $cat->cat_id;?>">
                        <?php if(!empty($cat_name[$this->session->userdata('lan')])):?>
                        <?php echo $cat_name[$this->session->userdata('lan')]['title'];?></option>
                        <?php else:
                            echo 'Không tồn tại tiêu đề danh mục cho ngôn ngữ hiện tại';
                            endif;
                        ?>
                    <?php endforeach?>
                <?php endif?>
            </select>
            <label class="checkbox">
                <input type="checkbox" name="is_feature" value="1" <?php echo $is_feature==1?"checked='checked'":"" ?>/> Is Feature
            </label>
     <label for="access">Access:</label>
            <select name="access">
                <option value="0">All</option>
                <?php if(count($roles)>0):?>
                    <?php foreach($roles as $rol):?>
                        <option <?php echo $rol->rolesID==$access?"selected='selected'":"" ?> value="<?php echo $rol->rolesID;?>"><?php echo $rol->name;?></option>
                    <?php endforeach?>
                <?php endif?>
            </select>
            <label class="checkbox"><input value="1" <?php echo $is_menu==1?"checked='checked'":"" ?> type="checkbox"  name="is_menu" />Display as menu</label>
            <label for="ordering">Ordering on menu</label>
        <input type="text" name="ordering" id="ordering" value="<?php echo $ordering?>" />
        <label for="ordering">Liên kết ngoài</label>
        <input type="text" name="link" id="link" value="<?php echo $link?>" />
        <label for="metakey">Metakey:</label>
        <input type="text" name="metakey" id="metakey" />
        <label for="metadesc">Metadesc:</label>
        <textarea name="metadesc" id="metadesc" class="large"></textarea>
        <div class="modal-footer">
    <input type="submit" class="btn btn-primary"  value="Save"/>
    <a href="<?php echo base_url().'/administrator/category/'.$cat_type ?>" class="btn">Cancel</a>
    <input type="hidden" name="action"  value="<?php echo $action ?>" id="action" />
    <input type="hidden" name="cat_id"  value="<?php echo $cat_id ?>" id="action" />
  </div> 
  </div>
</form>